package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.Construction;
import com.hengxinguotong.zhihuichengjian.treeview.RecyclerAdapter;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @CopyRight 恒信国通信息科技
 * @Author WuLei
 * @Date 2019/1/22
 */

public class EnterpriseConstructionAdapter extends RecyclerAdapter<Construction, EnterpriseConstructionAdapter.EnterpriseConstructionViewHolder> {
    private EnterpriseUserAdapter.OnChildHeadClickListener onChildHeadClickListener;
    private EnterpriseUserAdapter.OnChildDeleteClickListener onChildDeleteClickListener;
    private boolean hasDelete = false;

    public EnterpriseConstructionAdapter(Context context, List<Construction> dataList) {
        super(context, dataList);
    }

    public void setHasDelete(boolean hasDelete) {
        this.hasDelete = hasDelete;
    }

    public void setOnChildHeadClickListener(EnterpriseUserAdapter.OnChildHeadClickListener onChildHeadClickListener) {
        this.onChildHeadClickListener = onChildHeadClickListener;
    }

    public void setOnChildDeleteClickListener(EnterpriseUserAdapter.OnChildDeleteClickListener onChildDeleteClickListener) {
        this.onChildDeleteClickListener = onChildDeleteClickListener;
    }

    @Override
    public EnterpriseConstructionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_enterprise_construction, null);
        return new EnterpriseConstructionViewHolder(view);
    }

    @Override
    public void onBindViewHolder(EnterpriseConstructionViewHolder holder, int position) {
        holder.bindData(position);
    }

    public class EnterpriseConstructionViewHolder extends RecyclerAdapter.BaseViewHolder<Construction>{
        @BindView(R.id.construction_name)
        HXTextView constructionName;
        @BindView(R.id.user_rv)
        RecyclerView userRv;

        EnterpriseUserAdapter adapter;

        public EnterpriseConstructionViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void bindData(int position) {
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            itemView.setLayoutParams(params);
            Construction construction = dataList.get(position);
            if(position == 0){
                constructionName.setText(construction.getConstructionName() + "---" + construction.getConstructionName()) ;
            }else {
                constructionName.setText(construction.getConstructionName());
            }
            adapter = new EnterpriseUserAdapter(context, construction.getUserList());
            adapter.setHasDelete(hasDelete);
            adapter.setOnChildDeleteClickListener(onChildDeleteClickListener);
            adapter.setOnChildHeadClickListener(onChildHeadClickListener);
            userRv.setAdapter(adapter);
            userRv.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
        }
    }


}
